package com.cdream.basic.algorithm.leetcode.dp;

import java.util.Arrays;

public class Question279 {
    public int numSquares(int n) {
        int[] nums = new int[101];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = i * i;
        }

        // 这是个完全背包
        // dp[i] 代表和为i的最小数量
        int[] dp = new int[n + 1];
        Arrays.fill(dp, n + 1);
        dp[0] = 0;

        for (int i = 1; i < nums.length && nums[i-1] <= n; i++) {
            int num = nums[i - 1];
            for (int j = num; j <= n; j++) {
                dp[j] = Math.min(dp[j], dp[j - num] + 1);
            }
        }

        return dp[n];
    }

    public static void main(String[] args) {
        int i = new Question279().numSquares(1);
    }
}
